import { _decorator, Component, Input, Label, Node } from 'cc';
import { EventManager } from '../manager/event';
import { GameConst } from '../config/game-param';
const { ccclass, property } = _decorator;

@ccclass('UIOver')
export class UIOver extends Component {
    @property(Label) overScore: Label

    static readonly prefabUrl: string
    static readonly bundleName: string

    private _callback: Function

    onLoad() {
        this.overScore.string = GameConst.CURRENT_SCORE.toString()
        
        this.node.on(Input.EventType.TOUCH_START, this.onTouchStart, this)
    }

    onTouchStart() {
        EventManager.emit('on-touch-game-over')
        this.node.active = false
    }

    show(callback: Function) {
        this._callback = callback
        this.node.active = true
    }

    hide() {
        this.node.active = false
    }

    clickToClose() {
        this.node.active = false
        this._callback()
    }

    onDestroy() {
        this.node.off(Input.EventType.TOUCH_START, this.onTouchStart, this)
    }
}


